package org.n.shop.controller;

import lombok.AllArgsConstructor;
import org.n.shop.result.RestResult;
import org.n.shop.service.CommodityService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@AllArgsConstructor
@RequestMapping("/commodity")
public class CommodityController {
    private CommodityService commodityService;

    @RequestMapping("/all")
    public RestResult all(@RequestParam int page,
                          @RequestParam int pageSize,
                          @RequestParam(required = false) String key,
                          @RequestParam(required = false, defaultValue = "0") int orderBy,
                          @RequestParam(required = false, defaultValue = "0") int type) {
        return commodityService.all(page, pageSize, key, orderBy, type);
    }

    @RequestMapping("/id")
    public RestResult selectById(@RequestParam("id") int id) {
        return commodityService.selectById(id);
    }
}
